package com.javawork.juc.five;

import java.util.concurrent.atomic.LongAccumulator;
import java.util.concurrent.atomic.LongAdder;

/**
 * @author zhangxiaolu
 * @since 2023-02-12 19:07
 */
public class LongAdderApiDemo {

    public static void main(String[] args) {
        LongAdder longAdder = new LongAdder();//只能从0开始的加法
        longAdder.increment();
        longAdder.increment();
        longAdder.increment();
        System.out.println(longAdder.sum());

        LongAccumulator longAccumulator = new LongAccumulator((x, y) -> x + y, 0);//初始值为0，入参加初始值
        longAccumulator.accumulate(1);//1
        longAccumulator.accumulate(3);//4
        System.out.println(longAccumulator.get());
    }
}
